import React from 'react';

import { createStore } from 'redux'

//这是redux的原始state
const tiger = 10000

//这是action
const increase = {
    type: '涨工资'
}
const decrease = {
    type: '扣工资'
}

//这是reducer
const reducer = (state = tiger, action) => {
    switch (action.type) {
        case '涨工资':
            return state += 100;
        case '扣工资':
            return state -= 100;
        default:
            return state;
    }
}

//创建store
const store = createStore(reducer);

console.log(store.getState())

//订阅事件
store.subscribe(() =>
    console.log(store.getState())
);

//派发事件
//store.dispatch(increase)

class Login extends React.Component {

    render() {
        return (
            <div onClick={() => { store.dispatch(increase) }}>Login</div>
        );
    }
}
export default Login;